#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START libzio
# depends: bzip2
# depends: xz
# depends: zlib
# why: ALT specific patch to texinfo

rm -rf build/libzio
cp -a libzio build/
# libzio makefile is even worse than autocrap
make -C build/libzio \
	CC=${TARGET}-gcc \
	LIBS="-L${stage}${prefix}/${target_libdir} -lbz2 -lz -llzma" \
	CFLAGS="$CFLAGS -D_GNU_SOURCE -D_REENTRANT -DHAVE_FOPENCOOKIE -DHAS_ZLIB_H -DHAS_BZLIB_H -DHAS_LZMA_H"  \
	RPMOPTFLAGS='-O2 -g' \
	INCLUDES="-I${stage}${prefix}/include" \
	prefix=$prefix \
	libdir=$prefix/${target_libdir} \
	DESTDIR=$stage \
noweak shared install-shared install-data

LIBS=`${TARGET}-objdump -p ${stage}${prefix}/${target_libdir}/libzio.so | \
	sed -rne 's/^[[:space:]]*NEEDED[[:space:]]+(.+)$/\1/p' | sort -u`

case $LIBS in
	*libz.so.*)
		;;
	*)
		echo '*** Error: libzio is NOT linked with libz.so' >&2
		exit 1
		;;
esac

case $LIBS in
	*libbz2.so.*)
		;;
	*)
		echo '*** Error: libzio is NOT linked with libbz2.so' >&2
		exit 1
		;;
esac

case $LIBS in
	*liblzma.so.*)
		;;
	*)
		echo '*** Error: libzio is NOT linked with libbz2.so' >&2
		exit 1
		;;
esac

# RECIPE END libzio
